﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XingLucifer.IBase;

namespace XingLucifer.Devices.Devices
{

    public class CircuitTesterDrv : IDevices
    {
        private ICommunication _com;
        byte[] irCmd = Encoding.Default.GetBytes("LCTest:MEASure:IR?\r\n");
        byte[] currentCmd = Encoding.Default.GetBytes("LCTest:MEASure:LC?\r\n");
        byte[] voltageCmd = Encoding.Default.GetBytes("LCTest:MEASure:VMON?\r\n");
        Dictionary<string, string> keyValuePairs = new Dictionary<string, string>()
        {
            { "IR", "LCTest:MEASure:IR?\r\n"},
            { "Current", "LCTest:MEASure:LC?\r\n"},
            { "Voltage", "LCTest:MEASure:VMEAS?\r\n" }
            //{ "Voltage", "LCTest:MEASure:VMON?\r\n" }
        };
        private CancellationTokenSource _token;
        public CircuitTesterDrv(ICommunication com, CancellationTokenSource token)
        {
            _com = com;
            _token = token;
        }

        public void Close() => _com.Close();

        public bool Open() => _com.Open();

        /// <summary>
        /// 读取短路测试仪值
        /// </summary>
        /// <param name="keyValuePairs"></param>
        /// <param name="timeoutDuration"></param>
        /// <returns></returns>
        public Dictionary<string, string> CircuitTesterReceive()
        {
            return _com.SendAndReceive(keyValuePairs);
        }


        public string Read()
        {
            return _com.Read();
        }

        public List<ushort> Read(string addr, int count)
        {
            throw new NotImplementedException();
        }

        public bool ReadAndReturnBit(string addr)
        {
            throw new NotImplementedException();
        }

        public TClass ReadClass<TClass>(int address, TClass obj = null, int count = 3) where TClass : class
        {
            throw new NotImplementedException("未实现");
        }

        public TValue ReadSingle<TValue>(int address, int length, int count = 1)
        {
            return default;
        }

        public string ReadString(string addr, int count)
        {
            throw new NotImplementedException();
        }

        public bool Write<T>(string addr, T[] values)
        {
            throw new NotImplementedException();
        }

        public bool WriteClass<TClass>(TClass value, int address, int count = 3) where TClass : class
        {
            throw new NotImplementedException("未实现");
        }

        public bool WriteSingle(object value, int address, int offset, int length, int count = 3)
        {
            throw new NotImplementedException("未实现");
        }

        public bool WriteString(string addr, string values)
        {
            throw new NotImplementedException();
        }

        public bool WriteStringAsUInt16(string addr, string values)
        {
            throw new NotImplementedException();
        }
    }
}
